package com.hyb.algorithm.data.struct.math;

/**
 * @BelongProject algorithm
 * @BelongPackage com.hyb.algorithm.data.struct.math
 * @Description 最大公约数
 * @ClassName GreatestCommonDivisor
 * @Author huyangbing
 * @Date 2025/2/19 17:30
 * @Version 1.0.0
 */
public class GreatestCommonDivisor {


    public static int getGreatestCommonDivisor(int a, int b) {

        int big = a > b ? a : b;

        int small = a < b ? a : b;

        if (big % small == 0) {
            return small;
        }

        for (int i = small / 2; i > 1; i--) {
            if (small % i == 0 && big % i == 0) {
                return i;
            }
        }
        return 1;
    }


    public static void main(String[] args) {
        System.out.println(getGreatestCommonDivisor(25, 5));
        System.out.println(getGreatestCommonDivisor(100, 80));
    }
}
